package com.shiro.Result;

import com.shiro.Result.model.ResultModel;
import com.shiro.enums.ResultEnum;

/**
 * Created with IntelliJ IDEA.
 * User: dengpeng
 * Date: 2018/6/29
 * Time: 10:15
 * Description: 统一返回
 */
public class BaseResult {

    /**
     * Description: 成功信息返回
     *
     * @param resultEnum code and description
     * @param result     返回的数据
     * @return ResultModel
     */
    public static ResultModel success(ResultEnum resultEnum, Object result) {

        ResultModel resultModel = new ResultModel();
        resultModel.setCode(resultEnum.getCode());
        resultModel.setDescription(resultEnum.getMsg());
        resultModel.setResult(result);
        return resultModel;
    }

    /**
     * Description: 成功信息返回无参数
     *
     * @return ResultModel
     */
    public static ResultModel success() {

        return BaseResult.success(ResultEnum.SUCCESS, null);
    }

    /**
     * Description: 成功信息返回默认 msg:success code:000000
     *
     * @return ResultModel
     */
    public static ResultModel success(Object result) {

        return BaseResult.success(ResultEnum.SUCCESS, result);
    }

    /**
     * Description: 错误信息返回
     *
     * @return see {@link ResultModel}
     */
    public static ResultModel fail(ResultEnum resultEnum) {

        ResultModel resultModel = new ResultModel();
        resultModel.setCode(resultEnum.getCode());
        resultModel.setDescription(resultEnum.getMsg());
        return resultModel;
    }

    /**
     * Description: 自定义返回
     *
     * @param code        状态码
     * @param description 说明
     * @param result      返回的数据
     * @return ResultModel
     */
    public static ResultModel costom(String code, String description, Object result) {

        ResultModel resultModel = new ResultModel();
        resultModel.setCode(code);
        resultModel.setDescription(description);
        resultModel.setResult(result);
        return resultModel;
    }

}
